var selectedValues = {};
var inputCheckboxElement = [];
function loadActionSelect(options) {
    if (options.selectElementsCount > 1) {
        inputCheckboxElement['checkAll'] = $("input[type='checkbox'][container='" + options.contenedor + "']#selectall");
    }
    inputCheckboxElement['checkRaw'] = $("input[type='checkbox'][container='" + options.contenedor + "'].ckeckRow");
    inputCheckboxElement.checkRaw.change(function() {
        if (options.selectElementsCount < 2)
        {
            inputCheckboxElement.checkRaw.prop('checked', false);
            selectedValues = {};
            $(this).prop('checked', true);
        }
        selectRow($(this).attr('id'), $(this).attr('container'));
    });
    if (inputCheckboxElement.checkAll)
    {
        inputCheckboxElement.checkAll.change(function() {
            $contenedorAll = $(this).attr('container');
            if ($(this).is(':checked'))
            {
                $("input[container='" + $contenedorAll + "'].ckeckRow").prop('checked', true);
            }
            else
            {
                $("input[container='" + $contenedorAll + "'].ckeckRow").prop('checked', false);
            }
            $.each(inputCheckboxElement.checkRaw, function() {
                if ($contenedorAll == $(this).attr('container'))
                {
                    selectRow($(this).attr('id'), $(this).attr('container'));

                }
            });
        });
    }
}
function updateCheckedRaw(container) {
    if (selectedValues[container])
    {
        $.each(selectedValues[container], function(index, value) {

            var check_row = $('input[container="' + container + '"]#ckb_' + value);
            if (check_row)
            {
                check_row.prop('checked', true);
                check_row.parent().parent().addClass('selected');
            }
        });
    }
}
function selectRow(element, contenedor)
{
    $elementCKB = $("input[id='" + element + "'][container='" + contenedor + "'].ckeckRow");
    if (!selectedValues[contenedor])
    {
        selectedValues[contenedor] = [];
    }
    if ($elementCKB.is(':checked'))
    {
        $elementCKB.parent().parent().addClass('selected');
        selectedValues[contenedor].push($elementCKB.val());
        console.log(selectedValues[contenedor]);
    }
    else
    {
        $elementCKB.parent().parent().removeClass('selected');
        deleteElemen(selectedValues[contenedor], $elementCKB.val());
    }
}
function deleteElemen(contenerArray, val) {
    $.each(contenerArray, function(index, value) {
        if (val == value)
        {
            contenerArray.splice(index, 1);
        }
    });
}
